/****************************************************
          File Name:socket_client.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Fri 26 Sep 2014 09:27:05 AM CST
*****************************************************/

#include"net.h"

int main(int argc, char *argv[])
{
    int sfd,bytes;
    struct sockaddr_un addr;
    char *buf;

    buf=malloc(SIZE);

    sfd=socket(AF_UNIX,SOCK_STREAM,0);
    if(sfd==-1)
        err("socket");
    if(memset(&addr,0,sizeof(struct sockaddr_un))==NULL)
        err("set to zero");
    addr.sun_family=AF_UNIX;
    if(strncpy(addr.sun_path,path,sizeof(path)-1)==NULL)
        err("copy path ");
    //if(bind(sfd,(struct sockaddr *)&addr,sizeof(struct sockaddr_un))==-1)
      //  err("bind");
    if(connect(sfd,(struct sockaddr *)&addr,sizeof(struct sockaddr_un))==-1)
        err("connect");
    while((bytes=read(STDIN_FILENO,buf,SIZE))>0)
        if(write(sfd,buf,bytes)!=bytes)
            err("write to socket");
    if(bytes==-1)
        err("read");
    exit(0);
}
